<% extend 'phone/base.html' %>


<% block 'head' : %>
<link rel="stylesheet" href="/dist/phone-pay.css">
<% end %>

<div class="am-padding am-text-center">
    <div id="pay" class="am-btn am-btn-success am-radius">支付</div>
</div>



<script type="text/plain" id="pay-info">
    <%- @payInfo %>
</script>


<script type="text/plain" id="wechatJsConfig">
    <%- @wechatJsConfig %>
</script>


<% block 'scripts': %>
<script src="/dist/phone-pay.js"></script>
<script>
    try {
        var $ = jQuery;
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {

            var payInfo = JSON.parse($('#pay-info').html());

            var paied = false;
            //公众号支付
            $('#pay').click(function () {
                if (paied) {
                    return;
                }
                paied = true;
                WeixinJSBridge.invoke('getBrandWCPayRequest', payInfo, function(res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                        alert('支付成功，正在跳转');
                        window.location = '/user/order-list';
                    }
                    paied = false;
                });
            }).trigger('click');
        }, false);
    } catch (ex) {
//        alert(JSON.stringify(ex));
    }
</script>
<!--<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>-->
<% end %>